-- card: 37143 from stack: in -- bmap block id: 0 -- flags: 0000 -- background id: 4755 -- name: -- part contents for background part 6 ----- text ----- 4.2 Objects & Messages -- part contents for background part 4 ----- text ----- Thus far we have not declared any variables whose type is a class. Such variables are called OBJECTS. In TC (but not in C++) it is illegal to declare an identifier which is itself an object. Rather, we must declare an identifier which is a pointer to an object of the desired class. Since this is understood for all TC objects, we will not bother to indicate in the identifier name that it is a pointer as we usually do (e.g. float *f_ptr). In fact, we will refer to the pointer as though it were the object itself. Student *jack; /* note: 'struct' is not needed */ Recall that defining a pointer to a data type allocates space only for a machine address; it does not allocate space for the data type - in this case a Student object - itself. In C++ the 'new' operator allocates space for the instance variables of an object and returns a pointer to this space. TC uses the new() function for this purpose. jack = new(Student); /* in C++ the parentheses are not required */ Unlike the case with variables having "automatic" storage class*, space allocated by the new() function (or in C++ the 'new' operator) is not deallocated upon completion -- part contents for background part 29 ----- text ----- 28174 -- part contents for background part 27 ----- text ----- Automatic storage -- part contents for background part 20 ----- text ----- Automatic storage - p77 -- part contents for background part 7 ----- text ----- 114